<script setup lang="ts">
import ShowDrawC from '@views/self-config/components/ShowDraw.vue'
import YkAdaptiveBox from '@yk/components/adaptive-box/YkAdaptiveBox.vue'
import { removeToken, setToken } from '@utils/authorization/token'
import wx from 'weixin-js-sdk'
import { WxUtil } from '@utils/wx-util'

const selfId = shallowRef('')
const route = useRoute()
const router = useRouter()

const adaptiveBoxRef = shallowRef()

onMounted(() => {
  WxUtil.isWxEnv().then((res) => {
    if (res) {
      document.title = '组态画面'
      if (route.query.id) {
        selfId.value = route.query.id.toString()
      } else {
        ElMessage.warning('参数异常')
        setTimeout(() => {
          (wx.miniProgram as NonNullable<any>).navigateBack()
        }, 2000)
      }
    } else {
      router.back()
    }
  })
})
function loadHandle () {
  adaptiveBoxRef.value.resize()
}

onBeforeRouteUpdate(() => {
  removeToken()
})

</script>

<template>
  <yk-adaptive-box ref="adaptiveBoxRef" mode="contain">
    <show-draw-c v-if="selfId" :self-id="selfId" @load="loadHandle" />
  </yk-adaptive-box>
</template>

<style scoped lang="scss">

</style>
